package li.webqq.api;

import li.http.Request;
import li.webqq.Const;
import li.webqq.util.StringUtil;

import org.apache.log4j.Logger;

/**
 * http://www.qqxieyi.com/fenxi_show.asp?id=25
 */
public class Poll2Request extends Request implements Const {
    private static final Logger logger = Logger.getLogger(Poll2Request.class);

    private String psessionid;

    private String ptwebqq;

    public void setPsessionid(String psessionid) {
        logger.info("setPsessionid=" + psessionid);
        this.psessionid = psessionid;
    }

    public void setPtwebqq(String ptwebqq) {
        logger.info("setPtwebqq=" + ptwebqq);
        this.ptwebqq = ptwebqq;
    }

    public Poll2Response execute() {
        logger.info("Poll2Request execute");

        // String r = StringUtil.build(R_POLL2, psessionid);
        String r = StringUtil.build(R_POLL2, ptwebqq, psessionid);
        System.out.println("r=" + r);

        super.setUrl(URL_POLL2);
        super.setReferer(URL_PROXY);
        super.setContentType(FORM_URLENCODED);

        String encoded_r = StringUtil.encode(r);
        System.out.println("encoded_r=" + encoded_r);
        super.setField("r", encoded_r);
        // super.setField("clientid", CLIENT_ID);
        // super.setField("psessionid", psessionid);

        return super.execute(new Poll2Response());
    }
}